package com.mall.search.service.repository;

import com.mall.pojo.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.binding.QuerydslPredicate;
import org.springframework.data.repository.query.Param;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.data.solr.repository.Highlight;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;
import org.springframework.data.solr.repository.SolrRepository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 */
public interface MySolrRepository extends SolrCrudRepository<SearchBean,String> {

    /**
     * 自定义查询
     * @param keyword
     * @return
     */
    @Query("item_title:?0")
    public List<SearchBean> findByItemTitle(String keyword);

    /**
     * 利用solr提供的存储库查询时以防接受参数有空格最好把空格拆分然后放到list或者map中，然后在操作
     * @param keywords
     * @param page
     * @return HighlightPage<SearchBean>
     * @Highlight(fields = "item_title"字段填写solr服务器上的字段
     */
    @Highlight(fields = "item_title" ,prefix = "<em style=\"color:red\">",postfix = "</em>")
    public HighlightPage<SearchBean> findByTitleContains(List<String> keywords ,Pageable page);

}
